#include<bits/stdc++.h>
using namespace std;
long long T,n,m,l,V,s,vis=1,vis2=1,ans1,ans2,v[10010],p[10010],d[10010],a[10010],fv=1,nd[100010];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]!=0){
                vis=0;
            }
            if(a<=0){
                vis2=0;
            }
        }
        for(int i=1;i<=m;i++)cin>>p[i];
        if(vis){
            for(int i=1;i<=n;i++){
                if(v[i]>V&&d[i]<=p[m]) ans1++;
            }
            if(ans1!=0) ans2=m-1;
            else ans2=m;
            cout<<ans1<<" "<<ans2<<endl;
            continue;
        }else if(vis2){
            for(int i=1;i<=n;i++){
                nd[i]=(d[i]+(V*V-v[i]*v[i]))/(2*a[i]);
                if((V*V-v[i]*v[i])%(2*a[i])!=0) fv=0;
            }
            for(int i=1;i<=n;i++){
                if(nd[i]<p[m]) ans1++;
                if(nd[i]==p[m]&&fv==1) ans1++;
            }
            if(ans1!=0) ans2=m-1;
            else ans2=m;
            cout<<ans1<<" "<<ans2<<endl;
            continue;
        }
    }
    return 0;
}
